#ifndef RESOURCEMANAGER_H
#define RESOURCEMANAGER_H

#include <cstdio>
#include <d3dx9.h>
#include <d3d9.h>
#include "Input.h"
#include "Sprite.h"
#include "Texture.h"
#include "ResourcePath.h"
#include "Audio.h"
#include "Camera.h"
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include "QTNode.h"

using namespace std;

class QTNode;
class GameObject;
class ResourceManager
{

private:

	static ResourceManager *m_resource ;
	ResourceManager();
	

public:

	// var
	LPD3DXSPRITE m_spriteHandler;
	LPDIRECT3DDEVICE9 m_pd3Device;
	HINSTANCE m_Hinst;
	HWND m_wndHandle;
	CInput *m_input;
	CTexture *m_texture;
	CAudio *m_audio;
	CCamera *m_camera;
	D3DXVECTOR2 m_posChar;

	int m_levelMap;
	int m_life;
	int m_heightMap;
	int m_widthMap;
	vector<GameObject*> listObinView;

	/*------    HUD Camera     -----*/
	CSprite *HUD_badge;

	/*--- Menu Resource ----*/
	CSprite *menu_bg;
	CSprite *menu_item1;
	CSprite *menu_item2;
	CSprite *menu_badge;

	CSound *music_menu_bg;

	/*--- Loading Resource ----*/
	CSprite *load_1p;
	CSprite *load_rest;
	CSprite *load_hi;
	CSprite *load_stage;
	CSprite *load_number;
	CSprite *load_nameStage;

	/*--- Play Resource ----*/
	
	// background
	CSprite *play_bg1;
	CSprite *play_bg2;

	//Object
	CSprite *cS_character;
	CSprite *cS_ground;
	CSprite *cS_obstacle;
	CSprite *cS_sniper;
	CSprite *cS_bragdeEagle;
	CSprite *cS_blockhouse;
	CSprite *cS_runman;
	CSprite *cS_item;

	/*-------- Background -------*/
	vector<int> map1_listTile;
	vector<int> map2_listTile;

	/*--------- Map --------*/
	vector<QTNode*> map1_listNode;
	vector<GameObject*> map1_listOb;

	// function
	~ResourceManager();
	static ResourceManager *getInstance();
	static void prepareManager(LPD3DXSPRITE, LPDIRECT3DDEVICE9, HINSTANCE, HWND, CInput*, CTexture*, CAudio*);

	void loadMenuResource();
	void loadMenuGraphics();
	void loadMenuAudio();
	void unloadMenuResource();

	void loadLoadingResource();
	void loadLoadingGraphics();
	void loadLoadingAudio();
	void unloadLoadingResource();

	void loadPlayResource();	
	void loadMap1();
	void loadMap2();
	void loadPlayGraphics();
	void loadPlayAudio();
	void unloadPlayResource();

	// load list cac tile tu file text
	vector<int> loadFileTextBG(string path);	
	// load list node tu file text
	vector<QTNode*> loadFileTextNode(string path);
	// load list object tu file text
	vector<GameObject*> loadFileTextOB(string path);
	// split string de add vo gameObject
	GameObject* splitTextPushOB(string str);
	// split string de add vo Node
	QTNode* splitTextPushNode(string str);

	void setLevelMap(int x){ m_levelMap; }

};



#endif